package action.album;

import java.util.ArrayList;
import java.util.List;

import model.Album;
import model.Page;
import DAO.AlbumDAO;
import DAO.DAOImple.AlbumImple;

import com.opensymphony.xwork2.ActionSupport;

public class AlbumAction extends ActionSupport {
	
	private Page page;
	
	private Album album;
	private List<Album> albumList = new ArrayList<Album>();
	
	/*
	 * 增加相册action
	 */
	public String addAlbum() {
		
		AlbumDAO albumDao = new AlbumImple();
		int result = albumDao.addAlbum(album);
		if(result == 1) {
			System.out.println("增加相册成功");
		} else {
			System.out.println("增加相册失败");
		}
		
		if(page == null) {
			page = new Page();
			page.setCurrentPage(1);
		}
		page = page.getPage("T_Album where state = 0", page.getCurrentPage(), 20);
		
		albumList = albumDao.getAlbumList(page);
		
		return SUCCESS;
	}
	
	/*
	 * 得到相册列表action
	 */
	public String getAlbumes() {
		
		if(page == null) {
			page = new Page();
			page.setCurrentPage(1);
		}
		page = page.getPage("T_Album where state = 0", page.getCurrentPage(), 20);
		
		AlbumDAO albumDao = new AlbumImple();
		albumList = albumDao.getAlbumList(page);
		
		return SUCCESS;
	}
	
	/*
	 * 删除相册action
	 */
	public String deleteAlbum() {
		
		if(page == null) {
			page = new Page();
			page.setCurrentPage(1);
		}
		page = page.getPage("T_Album where state = 0", page.getCurrentPage(), 20);
		
		AlbumDAO albumDao = new AlbumImple();
		albumDao.deleteAlbum(album.getId());
		
		System.out.println("删除成功");
		
		albumDao.getAlbumList(page);
		
		return SUCCESS;
	}

	public Album getAlbum() {
		return album;
	}

	public void setAlbum(Album album) {
		this.album = album;
	}

	public List<Album> getAlbumList() {
		return albumList;
	}

	public void setAlbumList(List<Album> albumList) {
		this.albumList = albumList;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}
	
}
